<template>
  <div class="icons">
    <swiper :options="swiperOption">
      <swiper-slide v-for="(page, index) in pages" :key="index">
        <div class="icon" v-for="item in page" :key="item.id">
          <img :src="item.imgUrl">
          <p>{{item.desc}}</p>
        </div>
       </swiper-slide>
    </swiper>
  </div>
</template>
<script>
export default {
  name: "HomeIcons",
  props: {
    list: Array
  },
  data() {
    return {
      swiperOption: {
        autoplay: false
      }
    };
  },
  computed: {
    pages() {
      const pages = [];
      this.list.forEach((item, index) => {
        const page = Math.floor(index / 8);
        if (!pages[page]) {
          pages[page] = [];
        }
        pages[page].push(item);
      });
      return pages;
    }
  }
};
</script>
<style lang="stylus" scoped>
@import '~styles/mixins.styl';

.icons >>> .swiper-contaner {
  height: 0;
  padding-bottom: 50%;
  background-color: pink;
}

.icons {
  margin-top: 0.4rem;
}

.icon {
  float: left;
  overflow: hidden;
  width: 25%;
  height: 0;
  padding-bottom: 25%;
  text-align: center;

  img {
    width: 55px;
  }

  p {
    ellipsis();
    margin-top: 0.2rem;
  }
}
</style>
